package com.chenjt.langchain4j.controller;

import com.chenjt.langchain4j.assistant.XiaozhiAgent;
import com.chenjt.langchain4j.bean.ChatForm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2025/4/25 15:40
 */
@Tag(name="小智")
@RestController
@RequestMapping("/xiaozhi")
public class XiaozhiController {


    @Autowired
    private XiaozhiAgent xiaozhiAgent;

//    @Operation(summary = "对话")
//    @PostMapping("/chat")
//    public String chat(@RequestBody ChatForm chatForm){
//
//        return xiaozhiAgent.chat(chatForm.getMemoryId(),chatForm.getMessage());
//    }


    /**
     * 流式输出
     * @param chatForm
     * @return
     */
    @Operation(summary = "对话")
    // 添加 produces 属性，将输出模式设置为流模型
    @PostMapping(value = "/chat",produces = "text/stream;chatset=utf-8")
    public Flux<String> chat(@RequestBody ChatForm chatForm){
        return xiaozhiAgent.chat(chatForm.getMemoryId(),chatForm.getMessage());
    }

}
